/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.ExtInfo;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.thread.LuceneThread;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONArray;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class UpdateAppPeople extends AbstractAction
/*     */ {
/*  34 */   private static Logger logger = Logger.getLogger(UpdateAppPeople.class
/*  35 */     .getName());
/*     */ 
/*  37 */   private String indexPath = null;
/*     */ 
/*     */   public UpdateAppPeople(AbstractHttpServlet servlet, String indexPath) {
/*  40 */     super(servlet);
/*  41 */     this.indexPath = indexPath;
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  48 */     User user = super.getLoginUser(request);
/*     */ 
/*  50 */     int oldBelongCustomerId = Util.str2Int(request
/*  51 */       .getParameter("oldBelongCustomerId"));
/*     */ 
/*  53 */     int customerId = Util.str2Int(request.getParameter("customerId"));
/*     */ 
/*  55 */     String companyName = request.getParameter("companyName");
/*  56 */     String peopleName = request.getParameter("peopleName");
/*  57 */     String peopleTitle = request.getParameter("title");
/*  58 */     int categoryId = Util.str2Int(request.getParameter("categoryId"));
/*  59 */     String peopleNote = request.getParameter("note");
/*     */ 
/*  61 */     int hasModifyRight = Util.str2Int(request
/*  62 */       .getParameter("visibleIsModify"));
/*     */ 
/*  64 */     int visible = Util.str2Int(request.getParameter("visible"));
/*  65 */     String permissionsId = request.getParameter("permissionsId");
/*  66 */     String oldPermissionsId = request.getParameter("oldPermissionsId");
/*     */ 
/*  68 */     String shareUserIds = request.getParameter("shareUserIds");
/*  69 */     String oldShareUserIds = request.getParameter("oldShareUserIds");
/*  70 */     String shareGroupIds = request.getParameter("shareGroupIds");
/*  71 */     String oldShareGroupIds = request.getParameter("oldShareGroupIds");
/*     */ 
/*  73 */     String tagIds = request.getParameter("tagIds");
/*     */ 
/*  75 */     if (1 == visible) {
/*  76 */       permissionsId = "";
/*     */     }
/*     */ 
/*  79 */     List extInfos = new ArrayList();
/*  80 */     StringBuffer deleteExtInfoIds = new StringBuffer();
/*     */     try {
/*  82 */       JSONArray array = JSONArray.fromObject(request
/*  83 */         .getParameter("extInfo"));
/*  84 */       if ((array != null) && (array.size() > 0)) {
/*  85 */         for (int i = 0; i < array.size(); i++) {
/*  86 */           ExtInfo item = new ExtInfo();
/*  87 */           item.id = 
/*  88 */             Util.getJSONIntValue(array.getJSONObject(i), "id");
/*  89 */           item.type = Util.getJSONIntValue(array.getJSONObject(i), 
/*  90 */             "type");
/*  91 */           item.info1 = Util.getJSONStringValue(
/*  92 */             array.getJSONObject(i), "info1");
/*  93 */           item.info2 = Util.getJSONStringValue(
/*  94 */             array.getJSONObject(i), "info2");
/*  95 */           item.info3 = Util.getJSONStringValue(
/*  96 */             array.getJSONObject(i), "info3");
/*  97 */           item.info4 = Util.getJSONStringValue(
/*  98 */             array.getJSONObject(i), "info4");
/*  99 */           if ((item.info1 != null) && (item.info1.trim().length() != 0))
/*     */           {
/* 102 */             extInfos.add(item);
/*     */           }
/*     */         }
/*     */       }
/* 106 */       array = JSONArray.fromObject(request.getParameter("deleteExtInfo"));
/* 107 */       if ((array != null) && (array.size() > 0))
/* 108 */         for (int i = 0; i < array.size(); i++) {
/* 109 */           if (deleteExtInfoIds.length() > 0) {
/* 110 */             deleteExtInfoIds.append(",");
/*     */           }
/* 112 */           deleteExtInfoIds.append(array.getInt(i));
/*     */         }
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 117 */       logger.warn("add company info failed", e);
/*     */     }
/*     */ 
/* 120 */     CustomerManager manager = new CustomerManager();
/* 121 */     int count = manager.updatePeople(oldBelongCustomerId, companyName, 
/* 122 */       customerId, peopleName, peopleTitle, categoryId, peopleNote, 
/* 123 */       hasModifyRight, visible, permissionsId, oldPermissionsId, 
/* 124 */       shareUserIds, oldShareUserIds, shareGroupIds, oldShareGroupIds, 
/* 125 */       tagIds, true, extInfos, deleteExtInfoIds.toString(), 
/* 126 */       user.userId, user.companyId);
/* 127 */     response.setContentType("text/html;charset=utf-8");
/* 128 */     PrintWriter out = response.getWriter();
/* 129 */     JSONObject jsonObject = new JSONObject();
/*     */ 
/* 131 */     if (count > 0) {
/* 132 */       jsonObject.put("error", "0");
/*     */ 
/* 135 */       new LuceneThread(this.indexPath, false).start();
/*     */     }
/*     */     else {
/* 138 */       jsonObject.put("error", "1");
/* 139 */       jsonObject.put("msg", "客户信息更新失败，请稍后重试");
/*     */     }
/* 141 */     out.println(jsonObject);
/* 142 */     out.flush();
/* 143 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.UpdateAppPeople
 * JD-Core Version:    0.6.1
 */